{% extends "base.html" %}
{% block head %}
	{{ super() }}
{% endblock head %}
{% block left %}
	{{ super() }}
{% endblock left %}
{% block right %}
	{{ super() }}
	<!-- 修改name（页面名称） -->
	{% set name = 'QA排期' %}
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>{{name}}</legend>
	</fieldset>
	<!-- 页面私有部分 -->
<form class="layui-form">

	<div class="site-demo-button" id="add" style="margin-bottom: 0;">
	<button data-method="offset" data-type="auto" class="layui-btn layui-btn-normal">新增设备</button>
	</div>


    <label class="layui-form-label">设备类型：</label><div class="layui-input-inline"><select name="devtype" lay-verify="required" lay-search=""><option value="">请选择设备类型</option><option value="0">手机</option><option value="1">其他</option></select></div>

</form>
<script>
 	layui.use(['form', 'layedit', 'laydate'], function(){
  		var form = layui.form

	layui.use('layer', function(){ //独立版的layer无需执行这一句
		var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
		//手机外借按钮弹窗触发
		var active = {
			offset: function(othis){
				var type = othis.data('type')
				,text = othis.text();
				var devid = othis.data('id');
				layer.open({
				type: 1
				,area: ['350px', '400px']
				,title:"新增设备"
				,offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
				,id: 'add '+devid //防止重复弹出
				,content:'<div class="layui-form-item" style="line-height:30px;margin-top: 20px"><label class="layui-form-label">设备名称：</label><div class="layui-input-block"><input type="text" name="devname" lay-verify="required" autocomplete="off" placeholder="请输入设备名称" class="layui-input"></div></div>\
<div class="layui-form-item" style="line-height:30px"><label class="layui-form-label">设备归属：</label><div class="layui-input-block"><input type="text" name="peoname" lay-verify="required" autocomplete="off" placeholder="请输入设备归属人" class="layui-input"></div></div>\
<div class="layui-form-item" style="line-height:30px"><label class="layui-form-label">设备版本：</label><div class="layui-input-block"><input type="text" name="deversion" lay-verify="required" autocomplete="off" placeholder="请输入设备版本" class="layui-input"></div></div>\
<label class="layui-form-label">设备说明：</label><div class="layui-input-block"><textarea name="devnote" placeholder="请输入设备说明" class="layui-textarea"></textarea></div>'
				,btn: '提交'
				,btnAlign: 'c' //按钮居中
				,shade: 0 //不显示遮罩
				,yes: function(index,layero){
					var devname = layero.find('input')[0].value;
					var peoname = layero.find('input')[1].value;
					var deversion = layero.find('input')[2].value;
					var devnote = layero.find('textarea')[0].value;


					var xmlhttp;
			        xmlhttp = new XMLHttpRequest();
 
			        var data ='{ "devname" : "'+ devname +'", "name" : "' + peoname + '","version" : "' + deversion + '", "notes" : "' + devnote + '"}';
			        xmlhttp.open("POST","device",true);
			        xmlhttp.send(data);
				 	layer.close(index);
					xmlhttp.onreadystatechange = function()
					{
				        if (xmlhttp.readyState == 4 && xmlhttp.status == 200 ) 
				            {
					            if (xmlhttp.responseText == 'ok')
					            {
					              location.reload();
					            }
					            else
					            {
					              alert('请求出错，请重试')
					            }
				          	}
					    }

					}
				});
			}
		};

		$('#add').on('click', 'button', function(){
			var othis = $(this), method = othis.data('method');
			active[method] ? active[method].call(this, othis) : '';
		})

	});
})
</script>


{% endblock right %}
<!-- 此模板现有部分，除页面名称外，其他均不可编辑 -->